class Project {
    String projectId
    String name
    String description    
    Date startDate
    Date endDate
    Lab lab
    
    static hasMany = [members : Employee, budgets : Budget]
    static mapping ={
        members cascade:"save-update"
    }
    static constraints = {
        projectId(size:1..20, unique:true, blank:false)
        name(size:1..200, blank:false, unique:true)
        description(size:0..4096)

        startDate(nullable:false,validator: {
            val, obj ->
            val < obj.properties['endDate']
            }
        )

        endDate(nullable:false,validator: {
            val, obj ->
            val > obj.properties['startDate']
            }
        )

        lab(nullable:false)
    }

     /* Add an employee in the project */
    public void addEmployee(Employee e){
        if(e != null){
            this.addToMembers(e);
        }
        else{
            System.out.println("Något gick fel:" + e)
        }
    }
    
    /* Delete an employee from the project */
    public void delEmployee(Employee e){
        this.removeFromMembers(e);
    }
    
    
    public Float calcTotalCost(){
        return 1.0
    }

    public Float calcTotalIncome(){
        return 1.0
    }

    public Float calcCurrentBalance(){
        return 100
    }

    public Float calcIncomingBalance(){
        return 1000
    }

    //Returns the status of the project based on date
    public String calcStatus()
    {
        Date now = new Date()
        if(this.startDate>now)
            return "Planned"

        if(this.endDate < now)
            return "Done"

        if(this.startDate <= now && this.endDate >= now)
            return "Progressing"

        return "Erroneous"
    }

    String toString(){"(${this.projectId}), ${this.name}"} 
}
